Skip to content

feat: add user agent header using gRPC interceptor#2199

Merged
aceppaluni merged 4 commits into
hiero-ledger:mainfrom
oGranny:fix/2169-add-user-agent-header-grpc
May 6, 2026
Merged

feat: add user agent header using gRPC interceptor#2199
aceppaluni merged 4 commits into
hiero-ledger:mainfrom
oGranny:fix/2169-add-user-agent-header-grpc

Conversation

@oGranny

@oGranny oGranny commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Description:
Added gRPC client interceptor, _UserAgentInterceptor, which adds an x-user-agent header to all outgoing gRPC requests, identifying the SDK and its version.

Related issue(s):

Fixes #2169

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

Signed-off-by: oGranny <ogranny.github.io@gmail.com>
Copilot AI review requested due to automatic review settings April 27, 2026 09:34
@oGranny
oGranny requested review from a team as code owners April 27, 2026 09:34
@oGranny
oGranny requested review from MonaaEid and exploreriii April 27, 2026 09:34
@codacy-production

codacy-production Bot commented Apr 27, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 9 complexity

Metric Results
Complexity 9

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a gRPC client interceptor to inject an SDK-identifying x-user-agent metadata header into all outgoing consensus-node and mirror-node gRPC calls, enabling node-side telemetry attribution (Fixes #2169).

Changes:

  • Introduces _UserAgentInterceptor that appends x-user-agent: hiero-sdk-python/{version|dev} to outgoing unary-unary and unary-stream RPCs.
  • Wraps consensus-node and mirror-node channels with grpc.intercept_channel(...) to apply the interceptor.
  • Adds unit tests covering header value construction and metadata injection behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/unit/channel_interceptor_test.py Adds unit tests validating user-agent value resolution and metadata injection for unary RPC types.
src/hiero_sdk_python/node.py Implements _UserAgentInterceptor and applies it to node gRPC channels.
src/hiero_sdk_python/client/client.py Applies the interceptor to the mirror-node gRPC channel.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/hiero_sdk_python/node.py Outdated
Comment thread src/hiero_sdk_python/node.py Outdated
@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 51ec31d7-747b-443e-9a16-47fd1320d878

📥 Commits

Reviewing files that changed from the base of the PR and between 1d1041d and 27131c3.

📒 Files selected for processing (1)
  • src/hiero_sdk_python/client/client.py

Walkthrough

Adds a gRPC client interceptor that injects an x-user-agent header set to hiero-sdk-python/{version} (falls back to dev) and applies it to SDK channels (consensus and mirror). Unit tests validate header construction and metadata insertion for unary-unary and unary-stream calls.

Changes

User-Agent Interceptor and Integration

Layer / File(s) Summary
Data / Constants
src/hiero_sdk_python/channels.py
Adds _UserAgentInterceptor that computes the user-agent value from importlib.metadata.version("hiero-sdk-python") with PackageNotFoundError fallback to "dev" and defines the x-user-agent header value.
Core Interceptor Logic
src/hiero_sdk_python/channels.py
Implements gRPC client interceptor methods intercept_unary_unary and intercept_unary_stream, injecting the x-user-agent header into outgoing call metadata while preserving existing metadata.
Channel Wiring — Node
src/hiero_sdk_python/node.py
Wraps node-created channels with grpc.intercept_channel(channel, _UserAgentInterceptor()) to apply the interceptor to consensus node calls.
Channel Wiring — Client / Mirror
src/hiero_sdk_python/client/client.py
Wraps the mirror node channel with grpc.intercept_channel(self.mirror_channel, _UserAgentInterceptor()) before constructing the mirror stub.
Tests
tests/unit/channel_interceptor_test.py
Adds unit tests verifying: user-agent value from installed version, fallback to dev when version lookup fails, preservation/augmentation of metadata for unary-unary calls, adding header when metadata is None for unary-stream calls, and that the interceptor implements required gRPC client interceptor interfaces.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a user agent header via gRPC interceptor, which is the primary focus of the PR.
Description check ✅ Passed The description is directly related to the changeset, explaining the addition of the _UserAgentInterceptor and referencing the related issue #2169.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #2169: implements _UserAgentInterceptor with x-user-agent header injection, includes version fallback to 'dev', supports UnaryUnary and UnaryStream call types, applies interceptor to both consensus and mirror node channels via grpc.intercept_channel, keeps changes minimal, and includes unit tests for header injection and version fallback.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the user-agent header feature: new channels.py interceptor, integration in node.py and client.py, and unit tests. No unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📋 Issue Planner

Built with CodeRabbit's Coding Plans for faster development and fewer bugs.

View plan used: #2169

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2012e306-221c-483d-882c-3b737276c1f5

📥 Commits

Reviewing files that changed from the base of the PR and between 9ff0ff9 and c068b1b.

📒 Files selected for processing (3)
  • src/hiero_sdk_python/client/client.py
  • src/hiero_sdk_python/node.py
  • tests/unit/channel_interceptor_test.py

Comment thread src/hiero_sdk_python/client/client.py Outdated
Comment thread src/hiero_sdk_python/node.py Outdated
Comment thread src/hiero_sdk_python/node.py Outdated
Comment thread tests/unit/channel_interceptor_test.py Outdated
Comment thread tests/unit/channel_interceptor_test.py Outdated
Signed-off-by: oGranny <ogranny.github.io@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@exploreriii exploreriii added step: 1st 1st stage of the review approval process reviewer: maintainer PR needs a review from the maintainer team labels Apr 27, 2026
@github-actions github-actions Bot added the skill: beginner Achievable by a fairly new comer that has already completed a couple of good first issues label May 1, 2026
@codecov

codecov Bot commented May 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2199      +/-   ##
==========================================
+ Coverage   93.73%   93.75%   +0.01%     
==========================================
  Files         145      145              
  Lines        9483     9508      +25     
==========================================
+ Hits         8889     8914      +25     
  Misses        594      594              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@manishdait

Copy link
Copy Markdown
Contributor

@oGranny, Please apply the pre-commit on the PR

@aceppaluni

Copy link
Copy Markdown
Contributor

@oGranny Please let us know if you need assistance applying pre-commit

Signed-off-by: oGranny <ogranny.github.io@gmail.com>
@oGranny

oGranny commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

@oGranny Please let us know if you need assistance applying pre-commit

Done, apologies for the delay.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/unit/channel_interceptor_test.py (1)

31-104: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add integration guards for grpc.intercept_channel usage in Client and _Node.

Current tests validate interceptor internals, but they don’t fail if channel wiring is accidentally removed from Client._init_mirror_stub() or _Node._get_channel(). Add unit tests that monkeypatch grpc.intercept_channel and assert it is invoked with _UserAgentInterceptor in both flows.

As per coding guidelines, "Unit tests should be extensive - test even if we don't expect users to use it currently."


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6ac91ab9-bcbe-45e9-9928-2629308b005c

📥 Commits

Reviewing files that changed from the base of the PR and between c068b1b and 1d1041d.

📒 Files selected for processing (4)
  • src/hiero_sdk_python/channels.py
  • src/hiero_sdk_python/client/client.py
  • src/hiero_sdk_python/node.py
  • tests/unit/channel_interceptor_test.py

@manishdait manishdait left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oGranny, Seems good to me, just update the branch

@manishdait manishdait added step: 2nd second stage of the review approval process and removed step: 1st 1st stage of the review approval process labels May 6, 2026
@aceppaluni
aceppaluni merged commit 343c42d into hiero-ledger:main May 6, 2026
29 checks passed
@aceppaluni

Copy link
Copy Markdown
Contributor

@oGranny Thank you!!

NssGourav pushed a commit to NssGourav/hiero-sdk-python that referenced this pull request May 14, 2026
Signed-off-by: oGranny <ogranny.github.io@gmail.com>
manishdait pushed a commit to manishdait/hiero-sdk-python that referenced this pull request May 18, 2026
Signed-off-by: oGranny <ogranny.github.io@gmail.com>
@exploreriii exploreriii modified the milestones: v0.2.7, v0.2.6 May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

reviewer: maintainer PR needs a review from the maintainer team skill: beginner Achievable by a fairly new comer that has already completed a couple of good first issues step: 2nd second stage of the review approval process

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement gRPC X-User-Agent Header for SDK Identification

5 participants